<?php
namespace app\admin\module;

use app\common\model\Storage;
use think\facade\Filesystem;
use think\File;

class FileModule{
    public static function upload(File $file,$originName=""){
        $path = Filesystem::disk('public')->putFile('images'.DIRECTORY_SEPARATOR.date('Ym'),$file,function (){
            return date('dHis').mt_rand(0,10000);
        });

        $url = Filesystem::getDiskConfig('public')['url'].'/'.$path;
        //保存信息到数据库中
        $data = [
            'origin_name'=>$originName,
            'size'=>$file->getSize(),
            'ext'=>$file->extension(),
            'path'=>$url,
            'type'=>0,
            'createtime'=>time(),
        ];

        Storage::create($data);

        return $url;
    }


}
